package com.xc.h05.service.wutao.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xc.h05.entity.Charge;
import com.xc.h05.entity.Chargetype;
import com.xc.h05.entity.Consult;
import com.xc.h05.mapper.ChargeMapper;
import com.xc.h05.mapper.ChargetypeMapper;
import com.xc.h05.mapper.ConsultMapper;
import com.xc.h05.service.wutao.ChargeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ChargeServiceImpl implements ChargeService {
    @Autowired
    private ChargeMapper chargeMapper;

   @Autowired
    private ChargetypeMapper chargetypeMapper;

   @Autowired
   private ConsultMapper consultMapper;
    @Override
    public int add(Charge charge) {
        int add = chargeMapper.add(charge);
        return add;
    }

    @Override
    public int delete(Integer id) {
        int delete = chargeMapper.delete(id);
        return delete;
    }

    @Override
    public int update(Charge charge) {
        int update = chargeMapper.update(charge);
        System.out.println (charge );
        return update;
    }

    @Override
    public List<Charge> findAll() {
        List<Charge> list = chargeMapper.findAll();
        return list;
    }


    @Override
    public int deleteByIds(List<Integer> ids2) {
        int i = chargeMapper.deleteByIds(ids2);
        return i;
    }

    @Override
    public PageInfo<Charge> findByPage(int pageNum, int pageSize, Charge charge) {
        PageHelper.startPage(pageNum,pageSize);
        List<Charge> list = chargeMapper.findByPage(charge);
        for(Charge c:list){
            Chargetype chargetype = chargetypeMapper.findById(c.getTypeId());
            c.setChargetype(chargetype);
        }
        for(Charge ca:list){
            Consult consult = consultMapper.findById2(ca.getConsultId());
            ca.setConsult(consult);
        }
        PageInfo<Charge> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }
}
